package de.hsb.ai.devil.domain;

import jade.content.onto.BCReflectiveIntrospector;
import jade.content.onto.BasicOntology;
import jade.content.onto.Ontology;
import jade.content.onto.SerializableOntology;
import jade.content.schema.AgentActionSchema;
import jade.content.schema.ConceptSchema;
import jade.content.schema.PrimitiveSchema;
import jade.content.schema.TermSchema;
import jade.domain.FIPAAgentManagement.ExceptionOntology;
import jade.domain.introspection.IntrospectionOntology;

import org.apache.log4j.Logger;

import de.hsb.ai.devil.domain.action.GetDelta;
import de.hsb.ai.devil.domain.action.SetDelta;
import de.hsb.ai.devil.domain.action.StartGame;
import de.hsb.ai.devil.domain.event.GameOver;

/**
 * Small ontolgy for the devil game.
 */
public class DevilOntology extends Ontology implements DevilVocabulary {
	
	private static final long serialVersionUID = -8324125743737333532L;
	
	private static final Ontology instance = new DevilOntology();
	
	public static Ontology getInstance() {
		return instance;
	}
	
	protected DevilOntology() {
		super(NAME, new Ontology[]{IntrospectionOntology.getInstance(), ExceptionOntology.getInstance(), SerializableOntology.getInstance()}, new BCReflectiveIntrospector());
		try {
			add(new ConceptSchema(GAME_OVER), GameOver.class);
			
			add(new AgentActionSchema(DELTA_GET), GetDelta.class);
			add(new AgentActionSchema(DELTA_SET), SetDelta.class);
			add(new AgentActionSchema(GAME_START), StartGame.class);
			
			ConceptSchema cs = (ConceptSchema) getSchema(GAME_OVER);
			cs.add(GAME_OVER_WINNER, (ConceptSchema) getSchema(BasicOntology.AID), ConceptSchema.MANDATORY);
			cs.add(GAME_OVER_MESSAGE, (PrimitiveSchema) getSchema(BasicOntology.STRING), ConceptSchema.OPTIONAL);
			
			AgentActionSchema as = (AgentActionSchema) getSchema(DELTA_GET);
			as.add(DELTA_GET_TOTAL, (PrimitiveSchema) getSchema(BasicOntology.INTEGER), AgentActionSchema.MANDATORY);
			as.setResult((TermSchema) getSchema(DELTA_SET));
			
			as = (AgentActionSchema) getSchema(DELTA_SET);
			as.add(DELTA_SET_DELTA, (PrimitiveSchema) getSchema(BasicOntology.INTEGER), AgentActionSchema.MANDATORY);
			
			as = (AgentActionSchema) getSchema(GAME_START);
			as.add(GAME_START_TOTAL, (PrimitiveSchema) getSchema(BasicOntology.INTEGER), AgentActionSchema.MANDATORY);
			as.add(GAME_START_PLAYER_A, (ConceptSchema) getSchema(BasicOntology.AID), AgentActionSchema.MANDATORY);
			as.add(GAME_START_PLAYER_B, (ConceptSchema) getSchema(BasicOntology.AID), AgentActionSchema.MANDATORY);
		} catch (Exception e) {
			Logger.getLogger(getName()).error("initalizing ontology", e);
		} 
	}
}
